#include <algorithm>
#include <iostream>
using namespace std;

const int kMaxN = 13;

bool used[kMaxN];
int friends[kMaxN][3];
int n, ans = kMaxN * kMaxN * 3;

void DFS(int dep, int cost, int dt) {
  if (dep == n || cost >= ans) {
    ans = min(ans, cost);
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      used[i] = true;
      int tmp = 0;
      for (int j : friends[i]) {
        if (used[j]) {
          tmp--;
        } else {
          tmp++;
        }
      }
      DFS(dep + 1, cost + dt, dt + tmp);
      used[i] = false;
    }
  }
}

int main() {
  freopen("haywire.in", "r", stdin);
  freopen("haywire.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> friends[i][0] >> friends[i][1] >> friends[i][2];
  }
  DFS(0, 0, 0);
  cout << ans << "\n";
  return 0;
}